import Vue from 'vue'
import Vuex from 'vuex'
// import creat from 'vuex-persistedstate'
Vue.use(Vuex)

export default new Vuex.Store({
  state: {
    token:localStorage.getItem('token') || null,
    isLogin:"",
    username:"请先登录"
  },
  getters: {
  },
  mutations: {
    setToken(state,val) {
      state.token = val;
      localStorage.setItem('token', val);
    },
    // token
    setuser(state,token){
      state.isLogin=JSON.parse(token);
      localStorage.setItem("token",JSON.parse(token));
    },
    // 用户名
    setusername(state,account){
      state.username=JSON.parse(account);
      localStorage.setItem("username",JSON.parse(account));
    },
  },
  actions: {
  },
  modules: {
  },
  // plugins:[creat({
  //   storage:window.sessionStorage,
  //   reducer(val){
  //     return {
  //       username:val.username
  //     }
  //   }
  // })]
})
